/* eslint-disable no-multi-spaces */
const Base = require('./base.js');

module.exports = class extends Base {
  async findAction() {
    const model = this.model('dict_item');
    const data = await model.order(['sort DESC']).where({type: this.get('type')}).select();

    return this.success(data);
  }
  async findProductInfoAction() {
    const data = await this.model('product_info').limit(5).where({name: ['LIKE', `%${this.get('key')}%`],  company_id: this.getLoginUserId()}).order(['id DESC']).select();
    return this.success(data);
  }
  async findVendorInfoAction() {
    const data = await this.model('vendor_info').limit(5).where({vendor_name: ['LIKE', `%${this.get('key')}%`], company_id: this.getLoginUserId()}).order(['id DESC']).select();
    return this.success(data);
  }
  async findCityAction() {
    if (this.get('id')) {
      const data = await this.model('area_list').where({id: this.get('id')}).find();
      return this.success(data);
    } else {
      const data = await this.model('area_list').select();
      return this.success(data);
    }
  }
};
